<template>
   <van-button
          v-if="!datas.is_followed"

            type="info"
            color="#3296fa"
            round
            size="small"
            icon="plus"
            @click="onFollow"
            :loading="followLoading"
          >关注</van-button>
          <van-button
          v-else

            round
            size="small"
            @click="onFollow"
            :loading="followLoading"
          >已关注</van-button>
</template>

<script>

import { addFollow, deleteFollow } from '@/api/user'
export default {
  name: 'kuangss',

  props: {
    datas: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      followLoading: false
    }
  },

  methods: {
    // 用户关注
    async onFollow () {
      try {
        this.followLoading = true // 展示关注按钮的 loading 状态
        if (this.datas.is_followed) {
          await deleteFollow(this.datas.aut_id)
        } else {
          await addFollow(this.datas.aut_id)
          // console.log(this.datas.aut_id);
        }
        this.datas.is_followed = !this.datas.is_followed
      } catch (error) {
        console.log(this.datas.is_followed)
        console.log(this.datas)
        console.log(error)
        let message = '操作失败，请重试！'
        if (err.response && err.response.status === 400) {
          message = '你不能关注你自己！'
        }
        this.$toast(message)
      }
      this.followLoading = false // 展示关注按钮的 loading 状态
    }
  }
}
</script>

<style>

</style>
